package com.ab.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

public class AbViewPagerAdapter extends PagerAdapter{
	
	private Context mContext;
	private ArrayList<View> mListViews = null;
	private HashMap <Integer,View> mViews = null;


	public AbViewPagerAdapter(Context context,ArrayList<View> mListViews) {
		this.mContext = context;
		this.mListViews = mListViews;
		this.mViews = new HashMap <Integer,View>();
	}

	@Override
	public int getCount() {
		return mListViews.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == (arg1);
	}

	@Override
	public Object instantiateItem(View container, int position) {
		((ViewPager) container).addView(mListViews.get(position));
		return mListViews.get(position);
	}

	@Override
	public void destroyItem(View container, int position, Object object) {
		if (mListViews.size() > 0) {
			if ((mListViews.size() - 1) >= position) {
				((ViewPager) container).removeView(mListViews.get(position));
			}
		}
	}
}